package com.hackerrank.challenges.journeytothemoon;

import java.util.Scanner;

public class Solution {
	private static int findRoot(int p[], int n) {
		int cn = n;
		while(p[cn] >= 0)
			cn = p[cn];
		if(n != cn)
			p[n] = cn;
		return cn;
	}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt(), I = in.nextInt(), p[] = new int[N], s = 0, c = 0;
		for(int i = 0; i < N; i++)
			p[i] = -1;
		for(int i = 0; i < I; i++) {
			int A = in.nextInt(), B = in.nextInt();
			int RA = findRoot(p, A), RB = findRoot(p, B);
			if(RA != RB) {
				p[RA] += p[RB];
				p[RB] = RA;
			}
		}
		for(int i = 0; i < N; i++) {
			if(p[i] < 0) {
				c += s * Math.abs(p[i]);
				s += Math.abs(p[i]);
			}
		}
		System.out.println(c);
	}
}
